package edu.scau.cxq.gp.quartz.job;

import edu.scau.cxq.gp.mapper.InventoryMapper;
import edu.scau.cxq.gp.quartz.entity.InventoryAlertBean;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;

/**
 * @description 整理庫存定時任務（quartz版）
 * @return
 * @author TLC
 */

public class SortInventoryTask extends QuartzJobBean {

    @Autowired
    private InventoryMapper inventoryMapper;

    @Autowired
    private InventoryAlertBean inventoryAlertBean;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //TODO 这里写定时任务的执行逻辑
        inventoryMapper.sortInventory();

        // 整理完库存了之后 开始查找有无商品库存低于预警阈值 将记录保存
        if (inventoryAlertBean.getIsOpen()) {
            inventoryMapper.findUnderThreshold(inventoryAlertBean.getThreshold());
        }

        System.out.println("定时任务执行时间："+new Date().toLocaleString());
    }
}